package com.ssy.lingxi.workflow.entity;


import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.workflow.handler.converter.JpaJsonToKeyValueBOConverter;
import com.ssy.lingxi.workflow.model.bo.KeyValueBO;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * （外部）流程定义
 * @author 万宁
 * @version 2.0.0
 * @date 2021-04-21
 */
@Entity
@Table(schema = "public", name = "wf_external_task_definition", indexes = {@Index(name = "wf_external_task_definition_process_key_idx", columnList = "processKey"), @Index(name = "wf_external_task_definition_task_type_idx", columnList = "taskType"), @Index(name = "wf_external_task_definition_task_name_idx", columnList = "taskName")})
public class ExternalTaskDefinition implements Serializable {
    private static final long serialVersionUID = -8792301941074119738L;

    /**
     * 主键名称id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="external_task_definition_seq")
    @SequenceGenerator(sequenceName="wf_external_task_definition_seq", name="external_task_definition_seq",allocationSize = 1)
    private Long id;

    /**
     * 流程Key
     */
    @Column(columnDefinition = "varchar(100)")
    private String processKey;

    /**
     * 流程名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String processName;

    /**
     * 流程类型 1-简单的流程 2-有子流程的流程，定义在ProcessTypeEnum中
     */
    @Column(columnDefinition = "int2")
    private Integer processType;

    /**
     * 流程中任务的步骤
     */
    @Column
    private Integer taskStep;

    /**
     * 步骤名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String taskName;

    /**
     * 任务类型，定义在TaskTypeEnum中
     */
    @Column
    private Integer taskType;

    /**
     * 跳转条件，如果没有则为-1
     */
    @Column
    private Integer agree;

    /**
     * Task执行后返回的状态
     */
    @Column
    private Integer status;

    /**
     * Task执行后返回的状态的描述
     */
    @Column(columnDefinition = "varchar(40)")
    private String statusDesc;

    /**
     * 角色类型，定义在ExternalTaskRoleTypeEnum中，默认为-1
     */
    @Column
    private Integer roleType;


    /**
     * 自定义的Extensions属性
     */
    @Convert(converter = JpaJsonToKeyValueBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<KeyValueBO> other;

    /**
     * 一对多双向关联内部任务
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "extTask", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.EAGER)
    private Set<InternalTaskDefinition> subTasks;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public String getProcessName() {
        return processName;
    }

    public void setProcessName(String processName) {
        this.processName = processName;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }

    public Integer getTaskStep() {
        return taskStep;
    }

    public void setTaskStep(Integer taskStep) {
        this.taskStep = taskStep;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public Integer getTaskType() {
        return taskType;
    }

    public void setTaskType(Integer taskType) {
        this.taskType = taskType;
    }

    public Integer getAgree() {
        return agree;
    }

    public void setAgree(Integer agree) {
        this.agree = agree;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStatusDesc() {
        return statusDesc;
    }

    public void setStatusDesc(String statusDesc) {
        this.statusDesc = statusDesc;
    }

    public Integer getRoleType() {
        return roleType;
    }

    public void setRoleType(Integer roleType) {
        this.roleType = roleType;
    }

    public List<KeyValueBO> getOther() {
        return other;
    }

    public void setOther(List<KeyValueBO> other) {
        this.other = other;
    }

    public Set<InternalTaskDefinition> getSubTasks() {
        return subTasks;
    }

    public void setSubTasks(Set<InternalTaskDefinition> subTasks) {
        this.subTasks = subTasks;
    }
}
